package com.cellulam.framework.mq.listener;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.cellulam.framework.core.exceptions.SysException;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 *
 */
public class MqConsumerHolder {

    public static final MqConsumerHolder holder = new MqConsumerHolder();

    private List<MqConsumeInfo> mqListeners = Lists.newArrayList();

    private Set<String> groups = Sets.newHashSet();

    private MqConsumerHolder() {

    }

    /**
     * @param listener
     */
    public void addMqConsumer(MqConsumeInfo listener) {
        if (groups.contains(listener.getGroupId())) {
            throw new SysException("存在重复group: " + listener.getGroupId());
        }
        this.groups.add(listener.getGroupId());
        mqListeners.add(listener);
    }

    /**
     * @return
     */
    public List<MqConsumeInfo> getMqListeners() {
        return new ArrayList<>(mqListeners);
    }

}
